/*
 * @Author: Your name
 * @Date:   2020-07-26 16:03:43
 * @Last Modified by:   Your name
 * @Last Modified time: 2020-07-26 16:14:23
 */
import {ADD_COUNTS, ADD_TO_CART, CHANGE_SELECT} from './mutations-types';
export default {
  addCart(context, payLoad){
    return new Promise(function(resolve, reject){
      let oldGoods = null;
      for(let item of context.state.cartList){
        if(item.id === payLoad.id){
          oldGoods = item;
        }
      }
      if(oldGoods){
        context.commit(ADD_COUNTS, oldGoods);
        resolve('商品数量+1');
      }else{
        context.commit(ADD_TO_CART, payLoad);
        resolve('添加购物车成功');
      }
      })
  },
  changeSelect(context, payLoad){
    context.commit(CHANGE_SELECT, payLoad);
  }
}